package com.lframework.xingyun.basedata.bo.product.costcard;

import com.lframework.starter.web.core.bo.BaseBo;
import com.lframework.starter.web.core.utils.ApplicationUtil;
import com.lframework.xingyun.basedata.entity.ProductCostCard;
import com.lframework.xingyun.basedata.entity.ProductCostCardDetail;
import com.lframework.xingyun.basedata.service.product.ProductCostCardDetailService;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
import java.util.stream.Collectors;
import lombok.Data;

/**
 * 商品成本卡详情
 *
 * @author zmj
 * @since 2024-01-01
 */
@Data
public class GetProductCostCardBo extends BaseBo<ProductCostCard> {

  /**
   * ID
   */
  @ApiModelProperty("ID")
  private String id;

  /**
   * 商品ID
   */
  @ApiModelProperty("商品ID")
  private String productId;

  /**
   * 成本卡名称
   */
  @ApiModelProperty("成本卡名称")
  private String name;

  /**
   * 成本卡描述
   */
  @ApiModelProperty("成本卡描述")
  private String description;

  /**
   * 状态
   */
  @ApiModelProperty("状态")
  private Boolean available;

  /**
   * 成本卡明细列表
   */
  @ApiModelProperty("成本卡明细列表")
  private List<ProductCostCardDetailBo> details;

  public GetProductCostCardBo() {

  }

  public GetProductCostCardBo(ProductCostCard dto) {

    super(dto);
  }

  @Override
  protected void afterInit(ProductCostCard dto) {

    // 查询成本卡明细
    ProductCostCardDetailService productCostCardDetailService = ApplicationUtil.getBean(
        ProductCostCardDetailService.class);
    List<ProductCostCardDetail> details = productCostCardDetailService.getByCostCardId(dto.getId());
    this.details = details.stream().map(ProductCostCardDetailBo::new).collect(Collectors.toList());
  }
} 